package com.zs.members.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gsj.common.pojo.R;
import com.zs.members.pojo.entity.Points;
import com.zs.members.dao.PointsMapper;
import com.zs.members.pojo.vo.PointsVo;
import com.zs.members.service.PointsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张硕
 * @since 2021-07-25
 */
@Service
public class PointsServiceImpl extends ServiceImpl<PointsMapper, Points> implements PointsService {

    @Autowired
    private PointsMapper pointsMapper;

    @Override
    public R get(Long currentPage, Long pageSize, PointsVo pointsVo) {
        QueryWrapper<Points> wrapper = new QueryWrapper<>();
        if (pointsVo.getId()!=null){
           wrapper.like("tih.id",pointsVo.getId()) ;
        }
        if (StringUtils.isNotEmpty(pointsVo.getCreateTime())){
            wrapper.like("tih.create_time",pointsVo.getCreateTime());
        }
        if (pointsVo.getChangeType()!=null){
            wrapper.like("tih.change_type",pointsVo.getChangeType());
        }
        if (StringUtils.isNotEmpty(pointsVo.getOperateMan())){
            wrapper.like("tih.operate_man",pointsVo.getOperateMan());
        }
        if (pointsVo.getSourceType()!=null){
            wrapper.like("tih.source_type",pointsVo.getSourceType());
        }
        if (StringUtils.isNotEmpty(pointsVo.getUsername())){
            wrapper.like("tc.username",pointsVo.getUsername());
        }
        Page<Points> page = new Page<Points>(currentPage,pageSize);
        IPage<Points> pointsIPage = pointsMapper.get(page, wrapper);
        return R.ok().put("records",pointsIPage.getRecords()).put("total",pointsIPage.getTotal());
    }
}
